package com.puman.beautyfarmcounselor.ui.home.adpter;

import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.puman.beautyfarmcounselor.R;
import com.puman.beautyfarmcounselor.ui.customer.model.BackRecord;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Curry on 2015/6/12.
 */
public class BackrecordListAdapter extends RecyclerView.Adapter<BackrecordListAdapter.ViewHolder> {

    private List<BackRecord> backRecords = new ArrayList<BackRecord>();
    private Fragment fragment;

    public BackrecordListAdapter(Fragment fragment, List<BackRecord> backRecords) {
        this.fragment = fragment;
        this.backRecords = backRecords;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private final ImageView recordType;
        private final TextView recordTime;

        public ViewHolder(View v) {
            super(v);
            recordType = (ImageView) v.findViewById(R.id.record_type);
            recordTime = (TextView) v.findViewById(R.id.backRecordTime);
        }

        public ImageView getRecordType() {
            return recordType;
        }

        public TextView getRecordTime() {
            return recordTime;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.back_recordlist_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.getRecordTime().setText(backRecords.get(position).getDatetime());
        //1-电话 2-短信
        if (backRecords.get(position).getType() == 1) {
            holder.getRecordType().setImageDrawable(fragment.getActivity().getResources().getDrawable(R.drawable.customer_message));
        } else if (backRecords.get(position).getType() == 2) {
            holder.getRecordType().setImageDrawable(fragment.getActivity().getResources().getDrawable(R.drawable.tel));
        }
        holder.getRecordTime().setText(backRecords.get(position).getDatetime());

    }

    @Override
    public int getItemCount() {
        return backRecords.size();
    }


}
